package com.zjhome.cloudnote.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zjhome.cloudnote.constant.ErrorCode;
import com.zjhome.cloudnote.domain.DirInfo;
import com.zjhome.cloudnote.domain.NoteInfo;
import com.zjhome.cloudnote.domain.ResourceInfo;
import com.zjhome.cloudnote.exception.BaseException;
import com.zjhome.cloudnote.param.AckResult;
import com.zjhome.cloudnote.service.DirService;
import com.zjhome.cloudnote.service.ExplorerService;
import com.zjhome.cloudnote.service.NoteService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 笔记
 * 
 * @author zjhome
 *
 */
@RestController
@Api(value = "资源管理器")
@RequestMapping("/explorer")
public class ExplorerController extends BaseController {
	
	/**
	 * 资源管理器服务
	 */
	@Autowired
	private ExplorerService		explorerService;
	
	/**
	 * 文件夹服务
	 */
	@Autowired
	private DirService			dirService;
	
	
	/**
	 * 文件夹列表查询
	 * 
	 * @param did	父文件夹id
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/list")
	@ApiOperation(value = "资源列表")
	public List<ResourceInfo> getDirs( 
			@RequestParam(value = "did", required = false) String did,
			@RequestParam(value = "name", required = false) String name
			) throws Exception {
		String uid = this.getUserId();
		
		List<ResourceInfo> list = explorerService.selectSubDirInfo(did, name, uid);
				
		return list;
	}
	
	/**
	 * 更新资源
	 * 
	 * @param resourceInfo	资源信息
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/modres")
	@ApiOperation(value = "更新资源")
	public AckResult updateDir(ResourceInfo resourceInfo) throws Exception {
		explorerService.updateResource(resourceInfo, this.getUserId());
		
		return new AckResult(ErrorCode.ERR_NORMAL);
	}

	/**
	 * 删除资源
	 * 
	 * @param resourceInfo
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/delres")
	@ApiOperation(value = "删除资源")
	public AckResult deleteRes(ResourceInfo resourceInfo) throws Exception {
		explorerService.deleteResource(resourceInfo, this.getUserId());
		
		return new AckResult(ErrorCode.ERR_NORMAL);
	}
	
}
